﻿using B.S.DataBase.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.Write.API.Appicant.Command.MeonCommand;
using MediatR;

namespace B.S.DataBase.Write.API.Appicant.CommandHandler.MeonCommandHandler
{


    public class MeondeleteCommdandler : IRequestHandler<MeondeleteCommder, APIResult<object>>
    {


        private readonly IBaseRepository<TrunMeon> baseRepository;

        public MeondeleteCommdandler(IBaseRepository<TrunMeon> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public Task<APIResult<object>> Handle(MeondeleteCommder request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            result.Code = APIEnum.删除成功;
            result.Msg =APIEnum.删除成功.ToString();

            var lsit = baseRepository.GetAll().Result.FirstOrDefault(x => x.Trunid == request.Trunid && request.Suesser==(int)Suess.待审核);

            if (lsit != null)
            {
                lsit.Idester = true;
                baseRepository.Update(lsit);
                result.data = lsit;
            }
            else
            {
                result.Code = APIEnum.删除失败;
                result.Msg = "不能删除";


            }
            return Task.FromResult(result);
        }
    }
}
